﻿var enableProgressBar = true;
var processTimeTick, endAjax = false;

$(document).ready(function () {
    iniCSSFormInIE6();
    if ($.easyValidate) {
        var setting = "<div class=\"ui-state-error ui-corner-all alertPanel\"><span class=\"ui-icon ui-icon-alert alertIcon\"></span><span class=\"alertText\"></span></div>";
        $.easyValidate({
            summary: true,
            onError: function (message) {
                var a = $(this).next("div.alertPanel");
                if (a.length == 0) {
                    a = $(this).after(setting).next();
                }

                $(".alertText", $(a).addClass("ui-state-error")).text(message.join("<br>"));
                $(a).children("span").addClass("ui-icon-alert").removeClass("ui-icon-check");

            },
            errorEvent: false,
            onCorrect: function () {
                if ($(this).val().length == 0) {
                    return;
                }
             
                var a = $(this).next("div.alertPanel");
                if (a.length == 0) {
                    a = $(this).after(setting).next();
                }
                $(".alertText", $(a).removeClass("ui-state-error")).text("");
                $(a).children("span").removeClass("ui-icon-alert").addClass("ui-icon-check");
            }
        });
    }
    /// customer alert box.
    $("#ajaxErrorMessage").ajaxError(function (event, request) {
        $(this).html(request.responseText).dialog('open');
    }).dialog({ title: "出错", height: 450, width: 600, modal: true, autoOpen: false,
        buttons: { "确认": function () { $(this).dialog("close"); } }
    });
    $(".iconContainer", $("#topMenuBar")).hover(
					function () { $(this).addClass('ui-state-highlight'); },
					function () { $(this).removeClass('ui-state-highlight'); }
				);
    $("#progressbar").ajaxStart(
                function () {
                    if (enableProgressBar) {
                        endAjax = false;
                        processTimeTick = setTimeout(function () { if (!endAjax) { $("#progressbar").show(); } }, 1000);
                    }
                }
            ).ajaxStop(function () {
                if (enableProgressBar) {
                    endAjax = true;
                    $(this).hide();
                }
            });
});



function iniCSSFormInIE6() {
    if ($.browser.version === "6.0") {
        $(".cssform input[type='text'], .cssform input[type='password'], .cssform textarea")
        .addClass("cssform-input")
        .focus(function () { $(this).addClass("cssform-input-focus"); }).blur(
        function () { $(this).removeClass("cssform-input-focus"); }
        );
    }
}



